package com.greatwqs.wmall.order.client.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

/**
 * 订单状态：1 创建，3 支付超时，5 支付完成，9 取消，10 完成
 * 对应表：order.order_status
 *
 * @author wang-qingsong
 */
@Getter
@AllArgsConstructor
public enum OrderStatus {

    CREATED(1, "创建"),
    PAY_TIMEOUT(3, "支付超时"),
    PAY_COMPLETE(5, "支付完成"),
    CANCELED(9, "取消"),
    COMPLETE(10, "完成");

    private final int value;
    private final String name;

    public static OrderStatus of(int value) {
        return Arrays.stream(OrderStatus.values())
                .filter(orderType -> orderType.getValue() == value)
                .findFirst()
                .orElseThrow(() -> new IllegalArgumentException("OrderStatus invalid value: " + value));
    }
}
